import { Component, OnInit, ViewEncapsulation, ViewChild } from '@angular/core';
import { ApiService } from 'src/app/core/api';
import { ActivatedRoute, Router } from '@angular/router';
import { SwiperComponent, RatingConfig } from 'ngx-weui';

@Component({
	templateUrl: './index.component.html',
	styleUrls: ['./index.component.less'],
	encapsulation: ViewEncapsulation.None,
})
export class MhDelComponent implements OnInit {
	@ViewChild('swiper', { static: true }) swiper: SwiperComponent;
	showDailog = false;
	del;
	imgs: Array<any>;
	options: any = {
		init: true,
		observer: true,
		observeParents: true,
		effect: 'coverflow',
		slideShadows: false,
		pagination: {
			el: '.swiper-pagination',
		},
	};
	customIconsAndClassCog: RatingConfig = {
		max: 5,
		stateOff: 'off',
		stateOn: 'on',
		cls: 'rating'
	};

	constructor(
		private activedRoute: ActivatedRoute,
		private api: ApiService,
		private router: Router
	) {

	}

	getDel(data) {
		this.del = {
			id: 1, //# 漫画编号
			name: "lol",
			levelStar: 1.2,
			providerName: "宫崎骏jun",
			briefInfo: "千与千寻漫画简介",
			status: "Opened", //# 显示状态 Opened 显示，Closed 不显示
			isTrade: "Y", //#Y收费，N免费
			isFinish: "Y", //#Y完结, N未完结
			thumbnail: "../../../../assets/images/index/befor1.png",
			images: "../../../../assets/images/index/1.png,../../../../assets/images/index/2.png,../../../../assets/images/index/3.png",
			//#图片逗号隔开 3-12张
			cartoonChapterCount: 12,
			createTime: "2020-03-10 14:53:40"
		};
		this.imgs = this.del['images'].split(',');
		// this.api.post('漫画详情', data).then(res => {
		// 	this.del = res['data']['cartoonForUserDetail'];
		// 	this.imgs = this.del['images'].split(',');

		// }).catch(res => {
		// 	return res;
		// });
	}
	zhangJieList = [];
	getMhList(data) {
		for (let i = 0; i < 10; i++) {
			this.zhangJieList.push({
				id: 1,
				chapterName: "寻找七龙珠下",
				levelStar: 1.1,
				briefInfo: "创建漫画七龙珠",
				price: 13.00000000,
				isTrade: "Y",//#是否收费 Y是，N否
				thumbnail: "../../../../assets/images/index/listIMG2.png",
				createTime: "2020-03-10 14:56:20"
			})
		}
		// this.api.post('漫画章节列表', {
		// 	"pageNo": "1",
		// 	"cartoonId": data.id, //# 必填 漫画编号
		// 	"chapterName": ""
		// }).then(res => {
		// 	this.del = res['data']['cartoonForUserDetail'];
		// 	this.imgs = this.del['images'].split(',');
		// }).catch(res => {
		// 	return res;
		// });
	}

	ngOnInit() {
		this.getDel({ id: this.activedRoute.snapshot.queryParams.id });
		this.getMhList({ id: this.activedRoute.snapshot.queryParams.id });
	}

	onSel(teg) {
		this.router.navigate(['/picDel'], {
			queryParams: { cartoonChapterId: this.del['id'] }
		});
	}

	back() { history.back(); }
	payData = {
		relationType: "Cartoon", //# 平台产品类型 Game游戏, Cartoon漫画
		productId: '', //# 游戏编号, 漫画编号
		outTradeNo: "5", //# [漫画章节编号|其它外部订单号]
		itemName: '', //# [漫画章节名称|商品名称(装备,金币等)]
		orderAmount: '', //# 价格
		orderIp: "127.0.0.1",
		orderTime: "80200213120359", //# 下单时间 例 20201008013001
		paymentId: "1000", //# 支付方式编号
		tradePw: "" //# 支付密码
	};
	onSelZhangJie(item) {

		if (item.isTrade == 'Y') {
			this.payData.productId = item.id;
			this.payData.itemName = item.chapterName;
			this.payData.orderAmount = item.price;
			this.showDailog = true;
		} else {
			this.router.navigate(['/picDel'], {
				queryParams: { cartoonChapterId: this.del['id'] }
			});
		}
	}

	toPay() {
		this.api.post('支付订单', this.payData).then(res => {
			this.router.navigate(['/picDel'], {
				queryParams: { cartoonChapterId: this.payData['productId'] }
			});
		}).catch(res => {
			return res;
		});
	}
}
